Skip to content

Optimizing ModRegistryObjectTypeLoader and Everything Related to It#42

Open
tehtelev wants to merge 5 commits intoanegostudios:masterfrom
tehtelev:patch-3
Open

Optimizing ModRegistryObjectTypeLoader and Everything Related to It#42
tehtelev wants to merge 5 commits intoanegostudios:masterfrom
tehtelev:patch-3

Conversation

@tehtelev
Copy link
Copy Markdown

@tehtelev tehtelev commented Jan 2, 2026

The object type loading system was refactored, resulting in the following key improvements:

  1. Efficient parallel execution: Instead of launching multiple threads with manual task distribution, Parallel.ForEach with Partitioner is now used, ensuring automatic load balancing and optimal utilization of CPU cores.
  2. Lazy JSON resolution: The need for expensive DeepClone() for each object variant has been eliminated. Instead, a static Resolve method has been introduced that processes only those parts of the JSON that require modification, significantly reducing memory consumption and speeding up variant processing.
  3. Improved code structure: The logic is divided into clear steps-loading base types, processing them in parallel, and final registration. This improves readability and makes the code easier to maintain.
  4. Reliable thread management: The _gatheringCompleted flag has been introduced, eliminating fragile wait loops via Thread.Sleep, making execution more predictable and efficient.
  5. Enhanced error handling: errors in processing certain types no longer interrupt the entire process, but are isolated and logged, ensuring that other objects continue loading.

Also this PR is important here.

This PR also comes as a bonus.

Before (1.21.6):
image
image

After:
image
image

Replaced placeholder replacement method with optimized version for performance improvement during block and item initialization.
Update Registryobjecttypeloader
Refactor CreateResolvedType and related methods
@tehtelev tehtelev marked this pull request as ready for review January 2, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant